﻿using System;
using System.Collections.Generic;
using System.Text;
using ttlang.node;

namespace ttlang.builder.ts
{
    static class TypeConverter
    {

        readonly static Dictionary<string, string> tt2TSBaseType = new Dictionary<string, string>()
        {
            ["uint8"] = "number",
            ["uint16"] = "number",
            ["uint32"] = "number",
            ["int8"] = "number",
            ["int16"] = "number",
            ["int32"] = "number",
            ["float"] = "number",
            ["float64"] = "number",
            //["char"] = "char",//沒有char
            ["bool"] = "boolean",
            ["string"] = "string",
            ["Console"]="console",
        };

        public static string ConvertType(string typeStr)
        {
            if (tt2TSBaseType.ContainsKey(typeStr))
            {
                return tt2TSBaseType[typeStr];
            }
            return typeStr;
        }
        public static bool TryConvertMethod(StringBuilder coder, Node_Expr_Call call)
        {
            Node_Expr_Member mem = call.function as Node_Expr_Member;
            if(mem!=null&&mem.member is ttlang.semantic.TTMethod tm)
            {
                if(tm.container.name=="Console"&&tm.container.parentContainer==null)
                {
                    if(tm.name=="Warn")
                    {
                        coder.Append("ttbase.TTConsole.Warn");
                        NodeExporter.BuildCallParams(coder, call);
                        return true;
                    }
                    if (tm.name == "Log")
                    {
                        coder.Append("ttbase.TTConsole.Log");
                        NodeExporter.BuildCallParams(coder, call);
                        return true;
                    }
                    if (tm.name == "Error")
                    {
                        coder.Append("ttbase.TTConsole.Error");
                        NodeExporter.BuildCallParams(coder, call);
                        return true;
                    }
                }
            }
            
            return false;
        }

    }
}
